# encoding: utf-8
from ..aiauth.models import Users, Userinfo, Role


def font_user(request):
    user_id = request.session.get('user_id')
    context = {}
    if user_id:
        try:
            user = Users.objects.get(pk=user_id)
            role_id = Role.objects.get(role_id=user.role.role_id)
            Description = role_id.description
            userinfo = Userinfo.objects.get(userinfo_id=user.user_id)
            if userinfo.sex:
                sex = ord(userinfo.sex)
            else:
                sex = 0
            orgname = userinfo.organization.orgname
            data = {
                'user_id': user.user_id,
                'studentid': user.studentid,
                'student': user.username,
                'sex': sex,
                'Description': Description,
                'orgname': orgname,
            }
            context.update(data)
            context['front_user'] = user
        except:
            pass
    return context
